<%@ page contentType="application/xhtml+xml;charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld"%>

<!--${applicationScope.calendar}-->
<c:out value="Yearly view for ${year}"/><br/><br/>

<jsp:include page="/HidPages/keyList.jsp"/>

<table id="calendar" border="1">
    <tbody>
        <c:set var="otherYear" value="-1"/>
        <c:forEach var="i" begin="1" end="12">
            <c:set var="y" value="${i}"/>
            <c:if test="${y==1}"><c:set var="y" value="0${y}"/></c:if>
            <c:if test="${y==2}"><c:set var="y" value="0${y}"/></c:if>
            <c:if test="${y==3}"><c:set var="y" value="0${y}"/></c:if>
            <c:if test="${y==4}"><c:set var="y" value="0${y}"/></c:if>
            <c:if test="${y==5}"><c:set var="y" value="0${y}"/></c:if>
            <c:if test="${y==6}"><c:set var="y" value="0${y}"/></c:if>
            <c:if test="${y==7}"><c:set var="y" value="0${y}"/></c:if>
            <c:if test="${y==8}"><c:set var="y" value="0${y}"/></c:if>
            <c:if test="${y==9}"><c:set var="y" value="0${y}"/></c:if>
            <c:if test="${i mod 3 == 1}">
                <tr>
                </c:if>
                <td>
                    <table id="months" border="1" cellspacing="5" cellpadding="3">
                        <thead>
                            <tr>
                                <th>
                                    <c:out value="W"/>
                                </th>
                                <!--style="background-color:yellow"-->
                                <th colspan="7">
                                    <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean"
                                                  title="Monthly calendar for month ${months[i]}">
                                        <stripes:hidden name="year" value="${year}"/>
                                        <stripes:hidden name="monthStr" value="${i}"/>
                                        <c:forEach var="box" items="${newKeysList}">
                                            <stripes:hidden name="${box}" value="true"/>
                                        </c:forEach>
                                        <stripes:hidden name="viewType" value="monthlyView"/>
                                        <stripes:submit name ="viewMonthlyCalendar">
                                            <c:out value="${months[i]}"/>
                                        </stripes:submit>
                                    </stripes:form>
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <c:forEach var="weeks" end="0" items="${map[i]}">
                                <c:set var="visible" value="${false}"/>
                                <c:set var="weeks" value="${weeks.value}"/>
                                <c:forEach var="week" items="${weeks}">
                                    <c:if test="${week eq 1}">
                                        <c:set var="otherYear" value="${otherYear + 1}"/>
                                    </c:if>
                                    <tr>
                                        <th>
                                            <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean"
                                                          title="Weekly calendar for week ${week}">
                                                <stripes:hidden name="yearStr" value="${year + otherYear}"/>
                                                <stripes:hidden name="weekStr" value="${week}"/>
                                                <c:forEach var="box" items="${newKeysList}">
                                                    <stripes:hidden name="${box}" value="true"/>
                                                </c:forEach>
                                                <stripes:hidden name="viewType" value="weeklyView"/>
                                                <stripes:submit name ="viewWeeklyCalendar">
                                                    <c:out value="${week}"/>
                                                </stripes:submit>
                                            </stripes:form>
                                        </th>
                                        <c:forEach var="day" items="${map[i][week]}">
                                            <c:if test="${day == 1}">
                                                <c:set var="visible" value="${not visible}"/>
                                            </c:if>
                                            <c:choose>
                                                <c:when test="${visible}">
                                                    <!--<c:set var="test" value="${year}.${i}.${day}"/>-->
                                                    <c:set var="d" value="${day}"/>
                                                    <c:if test="${d==1}"><c:set var="d" value="0${d}"/></c:if>
                                                    <c:if test="${d==2}"><c:set var="d" value="0${d}"/></c:if>
                                                    <c:if test="${d==3}"><c:set var="d" value="0${d}"/></c:if>
                                                    <c:if test="${d==4}"><c:set var="d" value="0${d}"/></c:if>
                                                    <c:if test="${d==5}"><c:set var="d" value="0${d}"/></c:if>
                                                    <c:if test="${d==6}"><c:set var="d" value="0${d}"/></c:if>
                                                    <c:if test="${d==7}"><c:set var="d" value="0${d}"/></c:if>
                                                    <c:if test="${d==8}"><c:set var="d" value="0${d}"/></c:if>
                                                    <c:if test="${d==9}"><c:set var="d" value="0${d}"/></c:if>
                                                    <c:set var="pos" value="${year}${y}${d}${toolbox}"/>
                                                    <c:set var="test" value="${not empty view[pos]}"/>

                                                    <td>
                                                        <stripes:form beanclass="cz.muni.fi.xvano1.trinity.beans.CalendarViewActionBean"
                                                                      title="Daily calendar for day ${day} of month ${months[i]}">
                                                            <stripes:hidden name="year" value="${year}"/>
                                                            <stripes:hidden name="monthStr" value="${i}"/>
                                                            <stripes:hidden name="day" value="${day}"/>
                                                            <c:forEach var="box" items="${newKeysList}">
                                                                <stripes:hidden name="${box}" value="true"/>
                                                            </c:forEach>
                                                            <stripes:hidden name="viewType" value="dailyView"/>
                                                            <c:if test="${test}">
                                                                <stripes:submit name ="viewDailyCalendar"
                                                                                style="background-color:yellow;color:black">
                                                                    <c:out value="${day}"/>
                                                                </stripes:submit>
                                                            </c:if>
                                                            <c:if test="${not test}">
                                                                <stripes:submit name ="viewDailyCalendar">
                                                                    <c:out value="${day}"/>
                                                                </stripes:submit>
                                                            </c:if>
                                                        </stripes:form>
                                                    </td>
                                                    <!--
                                                    <td<c:if test="${test}">
                                                            bgcolor="blue"
                                                    </c:if>>
                                                    <c:out value="${day}"/>
                                                </td>
                                                    -->
                                                </c:when>
                                                <c:otherwise>
                                                    <td>
                                                        <c:out value=""/>
                                                    </td>
                                                </c:otherwise>
                                            </c:choose>
                                        </c:forEach>
                                    </tr>
                                </c:forEach>
                            </c:forEach>
                        </tbody>
                    </table>
                </td>
                <c:if test="${i mod 3 == 0}">
                </tr>
            </c:if>
        </c:forEach>
    </tbody>
</table>